package leetcode_day._2022._202204;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/4/5 19:43
 * 二进制表示中质数个计算置位
 * 算法：位运算
 */
public class _05_762 {

    static int[] nums;
    static {
        nums = new int[32];
        // 1 - 不是，0 - 是
        nums[0] = 1;
        for (int i = 2; i <= 32; i++)
            for (int j = 2; j <= i / 2; j++) if (i % j == 0) nums[i - 1] = 1;
    }
    public int countPrimeSetBits(int left, int right) {
        int ans = 0;
        for (int i = left; i <= right; i++) if (nums[getCntOnt(i) - 1] == 0) ++ans;
        return ans;
    }
    int getCntOnt(int x) {
        int res = 0;
        while (x > 0) {
            ++res;
            x -= x & (-x);
        }
        return res;
    }

}
